home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / g__~1 / gplibs15.zoo / stdstrbu.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  2.4 KB  |  69 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1992 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include <ioprivat.h>
  19. #include <g_config.h>
  20.  
  21. #if _G_NAMES_HAVE_UNDERSCORE
  22. #define UNDERSCORE "_"
  23. #else
  24. #define UNDERSCORE ""
  25. #endif
  26.  
  27. // To avoid problems depending on constructor order (and for
  28. // efficiency) the standard streambufs (and streams) are
  29. // constructed statically using C-style '{ ... }' initializers.
  30. // Since you're not allowed to do this for structs that
  31. // have virtuals, we define fake streambuf and stream classes
  32. // that don't have any C++-isms, and initialize those.
  33. // To initialize the vtable field of the standard filebufs,
  34. // we use the expression 'vt_filebuf' which must evaluate to
  35. // (the address of) the virtual function table for the
  36. // filebuf class.
  37.  
  38. #if !defined(vt_filebuf)
  39. #ifndef __GNUG__
  40. // This works for cfront.
  41. #define vt_filebuf __vtbl__7filebuf
  42. extern char vt_filebuf[1];
  43. #elif _G_DOLLAR_IN_LABEL
  44. extern char vt_filebuf[1] asm(UNDERSCORE "_vt$filebuf");
  45. #else
  46. extern char vt_filebuf[1] asm(UNDERSCORE "_vt.filebuf");
  47. #endif
  48. #endif /* !defined(vt_filebuf) */
  49.  
  50. struct _fake_filebuf {
  51.     struct __streambuf s;
  52.     char* vtable;
  53.     struct __file_fields f;
  54. };
  55.  
  56. #define DEF_STD(NAME, FD, CHAIN, FLAGS) \
  57.     _fake_filebuf NAME[1] = {{\
  58.        { _IO_MAGIC+_S_LINKED+_S_IS_FILEBUF+_S_IS_BACKUPBUF+FLAGS, \
  59.      0, 0, 0, 0, 0, 0, 0, 0, CHAIN, 0, 0, 0, 0, 0},\
  60.        vt_filebuf, {FD}}};
  61.  
  62. DEF_STD(_cin_sbuf, 0, 0, _S_NO_WRITES);
  63. DEF_STD(_cout_sbuf, 1, (streambuf*)_cin_sbuf, _S_NO_READS);
  64. DEF_STD(_cerr_sbuf, 2, (streambuf*)_cout_sbuf, _S_NO_READS);
  65.  
  66. DEF_STD(not_open_filebuf, -1, (streambuf*)0, _S_NO_READS+_S_NO_WRITES);
  67.  
  68. streambuf* streambuf::_list_all = (streambuf*)_cerr_sbuf;
  69.